package com.sa.token.oauth2.demo.satokenoauth2demo.config;

import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
import cn.dev33.satoken.oauth2.model.SaClientModel;
import org.springframework.stereotype.Component;

/**
 * Sa-Token OAuth2.0 整合实现
 */
@Component
public class SaOAuth2TemplateImpl extends SaOAuth2Template {

    /**
     * 根据 id 获取 Client 信息
      */
    @Override
    public SaClientModel getClientModel(String clientId) {
        // 此为模拟数据，真实环境需要从数据库查询
        if("10001".equals(clientId)) {
            return new SaClientModel()
                    .setClientId("10001")
                    .setClientSecret("aaaa-bbbb-cccc-dddd-eeee")
                    .setAllowUrl("http://127.0.0.1")
                    .setContractScope("userinfo");
        }
        return null;
    }

    @Override
    public boolean isGrant(Object loginId, String clientId, String scope) {
        return true;
    }

}

